/**
 * 
 */
package com.sinodata.bsm.center.service.resource;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.sinodata.bsm.center.cache.PropertyDisplayCache;
import com.sinodata.bsm.center.dao.BaseDao;
import com.sinodata.bsm.common.vo.PropertyDisplay;

/**
 * @author fanshengchao
 *
 */
@Service
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public class PropertyDisplayService {

    @Autowired
    private PropertyDisplayCache propertyDisplayCache;

    @Autowired
    private BaseDao baseDao;

    /**
     * 删除一个资源的所有指标别名
     * @param resId
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public void delByResId(Long resId) {
        List<PropertyDisplay> customProperty = propertyDisplayCache.getPropertysByResId(resId);
        for (int i = customProperty.size() - 1; i >= 0; i--) {
            PropertyDisplay prop = customProperty.get(i);
            propertyDisplayCache.remove(prop.getId());
            baseDao.delete(prop);
        }
    }
}
